package com.phy.core;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class DealXML {
	Element theBook = null, theElem = null, root = null;
	Document document = null;
	String FatherString="",first="",second="";
	public DealXML() throws ParserConfigurationException, SAXException,
			IOException {
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		factory.setIgnoringElementContentWhitespace(true);
		DocumentBuilder db = factory.newDocumentBuilder();
		InputStream is = DealXML.class
		.getResourceAsStream("/com/phy/core/map.xml");
		try{
		document = db.parse(is);
		}
		catch(IllegalArgumentException e){
			System.out.println("InputStream cannot be null");
		}
		root = document.getDocumentElement();
	}
	//在xml文件中利用关键字(mx记录、邮件系统返回值)判断邮件系统
	public String ArchieveSysName(String FatherString,String first,String second) {
		this.FatherString=FatherString;
		this.first=first;
		this.second=second;
		String content = "0";
		NodeList fList = document.getElementsByTagName(this.first);
		NodeList sList= document.getElementsByTagName(this.second);
		// 把xml里面的内容都打印出来
		int nodeLength = fList.getLength();
		int num = 0;
		Node abbr = null, SubStringNode = null;
		for (int k = 0; k < nodeLength; k++) {
			SubStringNode = fList.item(k);
			num++;
			if (this.FatherString.indexOf(SubStringNode.getTextContent()) != -1) {
				abbr = sList.item(k);
				content = abbr.getTextContent();
			}
		}
		return content;
	}
}
